//
//  DLMainTabBar.swift
//  微博
//
//  Created by mac on 15/12/15.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class DLMainTabBar: UITabBar
{
    let btnItemCount = 5
    
    override func layoutSubviews() {
        
        super.layoutSubviews()
        let width = self.frame.width / CGFloat(btnItemCount)
        let height = self.frame.height
        let frame = CGRect(x: 0, y: 0, width: width, height: height)
        
        print("---------------------")
        var index = 0
        for view in self.subviews
        {
            if view is UIControl && !(view is UIButton)
            {
                print(index)
                view.frame = CGRectOffset(frame, CGFloat(index) * width, 0)
                index += index == 1 ? 2 : 1
            }
            
        }
        
        //添加一个黄色的btn
        let addBtn = UIButton(frame:CGRectOffset(frame, 2 * width, 0))
        addBtn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        addBtn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        addBtn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        addBtn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        addSubview(addBtn)
        
    }
    
    

}
